package domain.extendMappingJoined;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

/**
 * 测试使用连接子类策略的继承映射
 */
public class test {
    public static  void main(String[] args){
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
        Configuration configuration = new Configuration().configure();
        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();

        Customer customer1 = new Customer("c1","comment1");
        Customer customer2 = new Customer("c2","comment2");
        Employee employee1 = new Employee("e1",1.0);
        Employee employee2 = new Employee("e2",2.0);
        Manager manager = new Manager("m1","depart");


        customer1.setEmployee(employee1);
        customer2.setEmployee(employee1);
        session.persist(customer1);
        session.persist(customer2);

        employee1.setManager(manager);
        employee2.setManager(manager);
        session.persist(employee1);
        session.persist(employee2);

        session.persist(manager);

        transaction.commit();
        session.close();
        sessionFactory.close();
    }


}
